{include file="common/head"}

<head>
    <title>订单出货</title>

    <style>
        a {
            text-decoration: none;
        }

        input {
            display: initial !important;
        }
    </style>
    <link rel="stylesheet" href="/static/flatpickr/flatpickr.min.css">
    <script src="/static/flatpickr/flatpickr.min.js"></script>
</head>

<body>
    <div class="container-fluid">
        <div class="row">
            <div class="col-2 fs-2">
                出货单管理
            </div>
            <div class="col">
                <form action="/order/delivery" method="post">
                    <div class="row" id="query_bar" style="height: 50px;line-height: 50px;">
                        <div class="col">
                            <label for="customer">客户：</label>
                            <select name="customer" class="form-control" style="width:140px;display:initial;">
                                <option value="">所有</option>
                                {foreach $customer_list as $k=>$v}
                                <option value="{$v['id']}" {if $v['id']==$customer} selected{/if}>{$v['name']}</option>
                                {/foreach}
                            </select>

                            <label for="sdate">日期：</label>
                            <input class="form-control" type="text" value="" id="sdate" name="sdate"
                                placeholder="开始日期" />

                            <label for="edate">
                                <input class="form-control" type="text" value="" id="edate" name="edate"
                                    placeholder="结束日期" />
                            </label>

                            <label for="po">客户PO#</label>
                            <input class="form-control" type="text" value="{$po}" id="po" name="po"
                                placeholder="客户订单号" />
                            </label>

                            <button type="button" class="btn btn-warning query">
                                <span class="bi-search"></span>
                            </button>
                        </div>
                    </div>
                </form>
            </div>
        </div>

        <table class="table table-sm table-hover table-striped table-bordered"
            style="width: inherit!important;;overflow: scroll;">

            <thead class="table-info">
                <th>序号<br>SN</th>
                <th>客户<br />Customer</th>
                <th>客户订单号<br />Customer PO#</th>
                <th>交货数<br />Delivery Qty</th>
                <th>司机/车牌<br />Driver contact</th>
                <th>司机电话<br /> Mobile</th>
                <th>交货时间<br />Delivery date</th>
                <th>制表人 <br /></th>
                <th>审核人</th>
                <th>备注<br />Memo</th>
                <th>出货单状态<br />Status</th>
                <th>
                    <a href="/order/delivery_add">
                        <button class="btn btn-primary">
                            <span class="bi-plus"></span>
                        </button>
                    </a>
                </th>
            </thead>
            <tbody>
                {foreach $list['data'] as $k=>$kv}
                <tr>
                    <td>{$k+1}</td>
                    <td>{$kv['customer_id_name']}</td>
                    <td>{$kv['order_no']}</td>
                    <td>{$kv['qty']}</td>
                    <td>{$kv['driver_name']}</td>
                    <td>{$kv['driver_mobile']}</td>
                    <td>{$kv['create_time']}</td>
                    <td>{$kv['creater_name']}</td>
                    <td>{$kv['check_by']}</td>
                    <td>{$kv['memo']}</td>
                    <td>{$kv['status_name']}</td>

                    <td class="text-nowrap">
                        <input type="checkbox" name="check_ids" value="{$kv['id']}" class='form-check-input' />
                        <button type="button" class="btn btn-sm btn-info list" id="{$kv['id']}">
                            <span class="bi-list"></span>
                        </button>

                        {if $kv['status']==1}
                        <button tyle="button" class="btn btn-sm btn-primary check" id="{$kv['id']}">
                            <span class="bi-check"></span>
                        </button>
                        
                        <button tyle="button" class="btn btn-sm btn-danger btn_cancel" id="{$kv['id']}">
                            <span class="bi-trash"></span>
                        </button>
                        {/if}


                    </td>
                </tr>
                {/foreach}

            </tbody>
        </table>
        {include file="common/pagination"}
    </div>

    </div>

</body>

<script type="text/javascript">

    $(document).ready(function () {

        var check_ids=[];

        flatpickr("#sdate", {});
        flatpickr("#edate", {});

        $(".sdate").flatpickr({
            enableTime: true,
            dateFormat: "Y-m-d H:i:s",
        });
        $(".edate").flatpickr({
            enableTime: true,
            dateFormat: "Y-m-d H:i",
        });
        
        $('.query').on('click',function(){
            $('form').submit();
        })

        $(".list").on('click', function () {
            var id = $(this).attr('id');
            check_ids=[];
             $(":checkbox:checked").each(function(){
                check_ids.push($(this).val())
                
            })
            console.log(check_ids)
            layer.open({
                type: 2,
                title: '订单明细',
                shadeClose: true,
                shade: false,
                maxmin: true, //开启最大化最小化按钮
                area: ['1200px', '600px'],
                content: '/order/delivery_list/id/' + id+"/ids/"+check_ids
            });
        })

        $(".check").on('click', function () {
            var oid = $(this).attr('id');
            layer.confirm('请在确认之前，仔细检查订单产品规格及数量！！！？', {
                btn: ['已经确认好了', '再检查一下'] //按钮
            }, function () {

                $.post("/order/order_check", {table:'delivery', id: oid, status: 2 }, function (res) {
                    if (res.code) {
                        //layer.open({content:'订单已确认!'});
                        location.reload();
                    } else {
                        layer.open({ content: '失败!' });
                    }
                });

            }, function () {
                layer.msg('取消操作!');
            });
        })

        $(".btn_cancel").on('click', function () {
            var oid = $(this).attr('id');
            layer.confirm('是否确认删除出货单？', {
                btn: ['Yes', 'No'] //按钮
            }, function () {

                $.post("/index.php/order/order_cancel", { table: 'delivery', id: oid,name:'出货单',slave_table:'delivery_list|delivery_id' }, function (res) {
                    console.log(res.msg)
                    if (res.code) {
                        location.reload();
                    } else {
                        layer.open({ 'content': res.msg });
                    }

                });

            }, function () {
                layer.msg('取消操作!');
            });

        })

    })



</script>

</body>

</html>